package page.Beans;

import java.sql.Date;
import java.sql.SQLException;

import basicTypes.RAClient;
import basicTypes.RAPenalty;

public class atribuirPen {
	private String user;
	private String dataIN;
	private int duracao;
	

	public String getDataIN() {
		return dataIN;
	}
	public void setDataIN(String dataIN) {
		this.dataIN = dataIN;
	}
	public int getDuracao() {
		return duracao;
	}
	public void setDuracao(int duracao) {
		this.duracao = duracao;
	}
	
	public String atribPen(loginBean x)throws SQLException{
		RAPenalty nova;
		RAClient usr;
		try{
			usr = x.getBd().db_getClient(x.getUser(), user).get(0);
		}
		catch(IndexOutOfBoundsException e){
			return "fail";
		}
		nova = new RAPenalty(usr.getId(), Date.valueOf(dataIN), duracao);
		
		try{
			x.getBd().db_addPenalty(x.getUser(), nova);
		}
		catch(SQLException e){
			System.out.println(e.getErrorCode());
			System.out.println(e.getMessage());
			System.out.println(e.getSQLState());
			return "fail";
		}
		
		return "suc";
	}
	public void setUser(String user) {
		this.user = user;
	}
	public String getUser() {
		return user;
	}
	
}
